package org.jeecg.modules.cascv.image.service.impl;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.cascv.image.service.merge.GaoweiguiService;
import org.jeecg.modules.cascv.image.service.merge.ImageService;
import org.jeecg.modules.cascv.image.service.merge.WurongqiService;
import org.jeecg.modules.cascv.image.service.merge.WurongqiweikongService;
import org.jeecg.modules.cascv.image.util.LaptopConstant;
import org.jeecg.modules.message.websocket.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Slf4j
public class MergeImageService {

    @Resource
    private WebSocket webSocket;

    public Result<Object> mergeImage(JSONObject jsonObject, String fileId) {
        //获取tableName   tableName:"TGTHYY0401_090H_31_CMPRAPP5"
        String tableName = jsonObject.getString("tableName");
        if(StringUtils.isEmpty(fileId)){ //如果fileId为空 将它赋值为tableName
            fileId = tableName;
        }
        if(StringUtils.equalsIgnoreCase(tableName, fileId)){ //比较不区分大小写，相同返回true
            LaptopConstant.idsFileTableName.put(tableName,"");
            //webSocket.pushMessage("REAL:" + tableName);//idsName
        }
        LaptopConstant.timeMap.put(fileId, System.currentTimeMillis() + 1000 * 10);
        //LaptopConstant：imageServiceMap定义Map<String, ImageService>类型的map 将ImageService存入
        ImageService imageService = LaptopConstant.imageServiceMap.get(tableName);
        if(imageService == null){
            return null;
        }
        imageService.merge(jsonObject, tableName, fileId);
        return null;
    }


}
